package com.systemutils;

import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.util.TypedValue;
import android.view.Window;
import android.view.WindowManager;

public class ActionBarUtils {
    /**
     * 状态栏显示或隐藏
     * true是隐藏、false是显示
     * @param activity
     * @param enable
     */
    public static void hideStausbar(Activity activity, boolean enable) {
        if (enable) {
            WindowManager.LayoutParams attrs =activity.getWindow().getAttributes();
            attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
            activity.getWindow().setAttributes(attrs);
        } else {
            WindowManager.LayoutParams attrs =activity.getWindow().getAttributes();
            attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
            activity.getWindow().setAttributes(attrs);
        }
    }

    /**
     * 获取系统标题栏的高度
     * @param context
     * @return
     */
    public static int getActionBarHeight(Context context){
        TypedValue typedValue = new TypedValue();
        if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true))
            return TypedValue.complexToDimensionPixelSize(typedValue.data,context.getResources().getDisplayMetrics());
        return 0;
    }

    /**
     * 设置状态栏透明
     */
    public static void setActionTransparent(Activity activity){
        //透明状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            Window window =activity.getWindow();
            window.setFlags(
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
                    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }
}
